package com.jingyanzi.member.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import com.jingyanzi.member.domain.IntegralLogDO;
import com.jingyanzi.member.domain.result.ResultDO;
import com.jingyanzi.member.domain.result.ResultSupport;

import com.jingyanzi.member.query.IntegRalLogQueryDO;
import com.jingyanzi.member.request.SingleRequest;
import com.jingyanzi.member.response.PageResponse;
import com.jingyanzi.member.service.IIntegralLogService;

@RestController
@RequestMapping("/api/integralLog")
public class IntegralLogController  {
	
	@Autowired
	private IIntegralLogService integralLogService;

	@RequestMapping(value = "/query.json", method = RequestMethod.POST)
	public PageResponse<IntegralLogDO> query(SingleRequest<IntegRalLogQueryDO> request) {
		
		IntegRalLogQueryDO integRalLogQueryDO = request.getData();
		integRalLogQueryDO.setPage(true);
		ResultDO result = integralLogService.query(integRalLogQueryDO);

		PageResponse<IntegralLogDO> response = new PageResponse<IntegralLogDO>();

		if (result.isSuccess()) {
			response.setPageindex(integRalLogQueryDO.getPageNO());
			response.setPagesize(integRalLogQueryDO.getPageRows());
			response.setTotal((Long) result.getModel(ResultSupport.SECOND_MODEL_KEY));
			response.setStatus(200);
			response.setVersion(1);
			response.setMsg("");
			response.setData((List<IntegralLogDO>)result.getModel(ResultSupport.FIRST_MODEL_KEY));
		} else {
			response.setVersion(1);
			response.setStatus(500);
			response.setMsg("");
		}

		return response;
	}
}
